package com.tt.service.impl;

import com.tt.mapper.CourseMapper;
import com.tt.mapper.StudentMapper;
import com.tt.pojo.Student;
import com.tt.service.StudentService;
import com.tt.vo.PageResult;
import com.tt.vo.SySResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
   @Autowired
   private StudentMapper mapper;
   @Autowired
   private CourseMapper courseMapper;
    @Override
    public PageResult getStudentList(PageResult pageResult) {
        long total = mapper.findTotal();
        //分页的结果
        int size = pageResult.getPageSize();//条数
        int start = (pageResult.getPageNum()-1) * size;//起始位置
        String name = pageResult.getName();//姓名查询
        String sex = pageResult.getSex();//性别查询
        List<Student> studentList = mapper.findStudentByPage(start,size,name,sex);
        return pageResult.setTotal(total).setRows(studentList);
    }

    @Override
    @Transactional
    public void addStudent(Student student) {
        mapper.insert(student);
    }

    @Override
    @Transactional
    public void deleteStudent(Long id) {
        courseMapper.deleteCourseById(id);
        mapper.deleteById(id);
    }

    @Override
    @Transactional
    public void updateStudentById(Student student) {
        mapper.updateById(student);
    }

    @Override
    public  List<Student> getStudentAll(String name) {
        return mapper.getStudentAll(name);
    }
}
